package org.example.springbootdemo02.controller;


import org.example.springbootdemo02.pojo.Account;
import org.example.springbootdemo02.pojo.Result;
import org.example.springbootdemo02.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/account")
public class AccountController {
    @Autowired
    private AccountService accountService;
    //查询所有账户
    @RequestMapping("/selectAll")
    public Result selectAll() {
        List<Account> accountList = accountService.selectAll();
        return Result.success(accountList);
    }
    @RequestMapping("/selectById")
    public Result selectById(Integer id) {
        Account account = accountService.selectById(id);
        return Result.success(account);
    }
    @RequestMapping("/selectByName")
    public Result selectByName(String name) {
        Account account = accountService.selectByName(name);
        return Result.success(account);
    }
    @RequestMapping("/insert")
    public Result insert(Account account) {
        accountService.insert(account);
        return Result.success();
    }
    @RequestMapping("/update")
    public Result update(Account account) {
        accountService.update(account);
        return Result.success();
    }
    @RequestMapping("/delete")
    public Result delete(Integer id) {
        accountService.delete(id);
        return Result.success();
    }
}
